package com.amigo.online.provider.sync.handle.data.solr.service.impl;

import java.util.List;

import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.core.query.Criteria;
import org.springframework.data.solr.core.query.Query;
import org.springframework.data.solr.core.query.SimpleQuery;
import org.springframework.data.solr.core.query.SolrDataQuery;
import org.springframework.stereotype.Service;

import com.amigo.online.provider.common.ConstantValue;
import com.amigo.online.provider.common.entity.VideoSolrInfo;
import com.amigo.online.provider.sync.common.AbstractGlobalService;
import com.amigo.online.provider.sync.handle.data.solr.service.VideoSolrService;

/**
 * @version: V 1.0.0
 * @Description: （video Solr 对象处理基础类）
 * @author: zxy  QQ:1363320658
 * @date: 2018年12月13日 下午6:23:26
 */
@Service
public class VideoSolrServiceImpl extends AbstractGlobalService implements VideoSolrService {

    @Autowired
    SolrTemplate solrTemplate;

    @Override
    public void insertObject(SolrInputDocument object) {
        UpdateResponse result = solrTemplate.saveDocument(ConstantValue.VIDEO_SOLR, object);
        solrTemplate.commit(ConstantValue.VIDEO_SOLR);
        logger.info("video solr 插入结果:" + result.toString());
    }

    @Override
    public long updateObject(String query, SolrInputDocument save) {
        UpdateResponse result = solrTemplate.saveDocument(ConstantValue.VIDEO_SOLR, save);
        solrTemplate.commit(ConstantValue.VIDEO_SOLR);
        logger.info("video solr 更新结果:" + result.toString());
        return 0;
    }

    @Override
    public long deleteObject(String query) {
        SolrDataQuery nequery = new SimpleQuery();
        nequery.addCriteria(Criteria.where("id").is(query));//.delete(collection, nequery)
        UpdateResponse result = solrTemplate.deleteByIds(ConstantValue.VIDEO_SOLR, query);
        solrTemplate.commit(ConstantValue.VIDEO_SOLR);
        logger.info("video solr 删除结果:" + result.toString());
        return 0;
    }

    /**
     * <p>Title: listFindbyIds</p>
     * <p>Description: </p>
     *
     * @param ids
     * @return
     * @see com.amigo.online.provider.sync.handle.data.solr.service.VideoSolrService#listFindbyIds(java.util.List)
     */
    @Override
    public List<VideoSolrInfo> listFindbyIds(List<Long> ids) {
        Query nequery = new SimpleQuery();
        nequery.addCriteria(Criteria.where("id").in(ids));
        List<VideoSolrInfo> result = solrTemplate.query(ConstantValue.VIDEO_SOLR, nequery, VideoSolrInfo.class);
        return result;
    }
	
	/*@Override
	public List<VideoSolrInfo> listFindbyIds(List<Long> ids){
		Query nequery = new SimpleQuery();
		nequery.addCriteria(Criteria.where("id").in(ids));
		List<VideoSolrInfo> result = solrTemplate.query(ConstantValue.VIDEO_SOLR, nequery, VideoSolrInfo.class);
		return result;
		
	}*/
	/*@Override
	public void totalUpdate(SolrInputDocument data) {
		solrTemplate.saveDocument(ConstantValue.VIDEO_SOLR, data);
		solrTemplate.commit(ConstantValue.VIDEO_SOLR);
		
	}

	@Override
	public void partUpdate(SolrInputDocument data) {
		solrTemplate.saveDocument(ConstantValue.VIDEO_SOLR, data);
		solrTemplate.commit(ConstantValue.VIDEO_SOLR);
		
	}*/
}
